Josh Dillon, Last Revised January 2022
This notebook examines an individual antenna's performance over a whole season. This notebook parses information from each nightly rtp_summarynotebook (as saved to .csvs) and builds a table describing antenna performance. It also reproduces per-antenna plots from each auto_metrics notebook pertinent to the specific antenna.
import os
from IPython.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
# If you want to run this notebook locally, copy the output of the next cell into the next line of this cell.
# antenna = "004"
# csv_folder = '/lustre/aoc/projects/hera/H5C/H5C_Notebooks/_rtp_summary_'
# auto_metrics_folder = '/lustre/aoc/projects/hera/H5C/H5C_Notebooks/auto_metrics_inspect'
# os.environ["ANTENNA"] = antenna
# os.environ["CSV_FOLDER"] = csv_folder
# os.environ["AUTO_METRICS_FOLDER"] = auto_metrics_folder
# Use environment variables to figure out path to the csvs and auto_metrics
antenna = str(int(os.environ["ANTENNA"]))
csv_folder = os.environ["CSV_FOLDER"]
auto_metrics_folder = os.environ["AUTO_METRICS_FOLDER"]
print(f'antenna = "{antenna}"')
print(f'csv_folder = "{csv_folder}"')
print(f'auto_metrics_folder = "{auto_metrics_folder}"')
antenna = "139" csv_folder = "/home/obs/src/H6C_Notebooks/_rtp_summary_" auto_metrics_folder = "/home/obs/src/H6C_Notebooks/auto_metrics_inspect"
display(HTML(f'<h1 style=font-size:50px><u>Antenna {antenna} Report</u><p></p></h1>'))
import numpy as np
import pandas as pd
pd.set_option('display.max_rows', 1000)
import glob
import re
from hera_notebook_templates.utils import status_colors, Antenna
# load csvs and auto_metrics htmls in reverse chronological order
csvs = sorted(glob.glob(os.path.join(csv_folder, 'rtp_summary_table*.csv')))[::-1]
print(f'Found {len(csvs)} csvs in {csv_folder}')
auto_metric_htmls = sorted(glob.glob(auto_metrics_folder + '/auto_metrics_inspect_*.html'))[::-1]
print(f'Found {len(auto_metric_htmls)} auto_metrics notebooks in {auto_metrics_folder}')
Found 68 csvs in /home/obs/src/H6C_Notebooks/_rtp_summary_ Found 66 auto_metrics notebooks in /home/obs/src/H6C_Notebooks/auto_metrics_inspect
# Per-season options
mean_round_modz_cut = 4
dead_cut = 0.4
crossed_cut = 0.0
def jd_to_summary_url(jd):
return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_Notebooks/blob/main/_rtp_summary_/rtp_summary_{jd}.html'
def jd_to_auto_metrics_url(jd):
return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_Notebooks/blob/main/auto_metrics_inspect/auto_metrics_inspect_{jd}.html'
this_antenna = None
jds = []
# parse information about antennas and nodes
for csv in csvs:
df = pd.read_csv(csv)
for n in range(len(df)):
# Add this day to the antenna
row = df.loc[n]
if isinstance(row['Ant'], str) and '<a href' in row['Ant']:
antnum = int(row['Ant'].split('</a>')[0].split('>')[-1]) # it's a link, extract antnum
else:
antnum = int(row['Ant'])
if antnum != int(antenna):
continue
if np.issubdtype(type(row['Node']), np.integer):
row['Node'] = str(row['Node'])
if type(row['Node']) == str and row['Node'].isnumeric():
row['Node'] = 'N' + ('0' if len(row['Node']) == 1 else '') + row['Node']
if this_antenna is None:
this_antenna = Antenna(row['Ant'], row['Node'])
jd = [int(s) for s in re.split('_|\.', csv) if s.isdigit()][-1]
jds.append(jd)
this_antenna.add_day(jd, row)
break
# build dataframe
to_show = {'JDs': [f'<a href="{jd_to_summary_url(jd)}" target="_blank">{jd}</a>' for jd in jds]}
to_show['A Priori Status'] = [this_antenna.statuses[jd] for jd in jds]
df = pd.DataFrame(to_show)
# create bar chart columns for flagging percentages:
bar_cols = {}
bar_cols['Auto Metrics Flags'] = [this_antenna.auto_flags[jd] for jd in jds]
bar_cols[f'Dead Fraction in Ant Metrics (Jee)'] = [this_antenna.dead_flags_Jee[jd] for jd in jds]
bar_cols[f'Dead Fraction in Ant Metrics (Jnn)'] = [this_antenna.dead_flags_Jnn[jd] for jd in jds]
bar_cols['Crossed Fraction in Ant Metrics'] = [this_antenna.crossed_flags[jd] for jd in jds]
bar_cols['Flag Fraction Before Redcal'] = [this_antenna.flags_before_redcal[jd] for jd in jds]
bar_cols['Flagged By Redcal chi^2 Fraction'] = [this_antenna.redcal_flags[jd] for jd in jds]
for col in bar_cols:
df[col] = bar_cols[col]
z_score_cols = {}
z_score_cols['ee Shape Modified Z-Score'] = [this_antenna.ee_shape_zs[jd] for jd in jds]
z_score_cols['nn Shape Modified Z-Score'] = [this_antenna.nn_shape_zs[jd] for jd in jds]
z_score_cols['ee Power Modified Z-Score'] = [this_antenna.ee_power_zs[jd] for jd in jds]
z_score_cols['nn Power Modified Z-Score'] = [this_antenna.nn_power_zs[jd] for jd in jds]
z_score_cols['ee Temporal Variability Modified Z-Score'] = [this_antenna.ee_temp_var_zs[jd] for jd in jds]
z_score_cols['nn Temporal Variability Modified Z-Score'] = [this_antenna.nn_temp_var_zs[jd] for jd in jds]
z_score_cols['ee Temporal Discontinuties Modified Z-Score'] = [this_antenna.ee_temp_discon_zs[jd] for jd in jds]
z_score_cols['nn Temporal Discontinuties Modified Z-Score'] = [this_antenna.nn_temp_discon_zs[jd] for jd in jds]
for col in z_score_cols:
df[col] = z_score_cols[col]
ant_metrics_cols = {}
ant_metrics_cols['Average Dead Ant Metric (Jee)'] = [this_antenna.Jee_dead_metrics[jd] for jd in jds]
ant_metrics_cols['Average Dead Ant Metric (Jnn)'] = [this_antenna.Jnn_dead_metrics[jd] for jd in jds]
ant_metrics_cols['Average Crossed Ant Metric'] = [this_antenna.crossed_metrics[jd] for jd in jds]
for col in ant_metrics_cols:
df[col] = ant_metrics_cols[col]
redcal_cols = {}
redcal_cols['Median chi^2 Per Antenna (Jee)'] = [this_antenna.Jee_chisqs[jd] for jd in jds]
redcal_cols['Median chi^2 Per Antenna (Jnn)'] = [this_antenna.Jnn_chisqs[jd] for jd in jds]
for col in redcal_cols:
df[col] = redcal_cols[col]
# style dataframe
table = df.style.hide_index()\
.applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
.background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=list(z_score_cols.keys())) \
.background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
.background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
.background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=list(redcal_cols.keys())) \
.applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
.applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
.applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=list(z_score_cols.keys())) \
.applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=list(z_score_cols.keys())) \
.bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
.format({col: '{:,.4f}'.format for col in z_score_cols}) \
.format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
.format('{:,.2%}', na_rep='-', subset=list(bar_cols.keys())) \
.set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])])
This table reproduces each night's row for this antenna from the RTP Summary notebooks. For more info on the columns, see those notebooks, linked in the JD column.
display(HTML(f'<h2>Antenna {antenna}, Node {this_antenna.node}:</h2>'))
HTML(table.render(render_links=True, escape=False))
| JDs | A Priori Status | Auto Metrics Flags | Dead Fraction in Ant Metrics (Jee) | Dead Fraction in Ant Metrics (Jnn) | Crossed Fraction in Ant Metrics | Flag Fraction Before Redcal | Flagged By Redcal chi^2 Fraction | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | Average Dead Ant Metric (Jee) | Average Dead Ant Metric (Jnn) | Average Crossed Ant Metric | Median chi^2 Per Antenna (Jee) | Median chi^2 Per Antenna (Jnn) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2459884 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 4.441880 | 1.674202 | 4.918153 | 3.414487 | 4.279715 | 2.331525 | -3.155565 | -2.022963 | 0.6723 | 0.6850 | 0.3882 | nan | nan |
| 2459883 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 6.764173 | 4.072724 | 40.963812 | 35.699041 | 5.155861 | 5.244433 | -5.801580 | -2.669634 | 0.6656 | 0.6861 | 0.3891 | nan | nan |
| 2459882 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 10.603717 | 6.462622 | 48.706503 | 41.679123 | 7.465988 | 7.432229 | -2.407451 | -0.488427 | 0.6665 | 0.6801 | 0.3827 | nan | nan |
| 2459881 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 7.002903 | 4.055062 | 54.537059 | 47.129606 | 14.796149 | 14.298215 | -5.027361 | 1.281351 | 0.7142 | 0.7366 | 0.3272 | nan | nan |
| 2459880 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 7.570058 | 4.330927 | 43.768277 | 38.030318 | 4.476612 | 4.461798 | -3.322607 | -2.126402 | 0.6656 | 0.6874 | 0.3928 | nan | nan |
| 2459879 | RF_maintenance | 0.00% | 0.00% | 0.00% | 0.00% | - | - | 3.172394 | 0.795421 | 2.108286 | 0.759708 | -0.431426 | -1.563879 | -4.344997 | -3.254741 | 0.6504 | 0.6766 | 0.4106 | nan | nan |
| 2459878 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 7.292762 | 4.719113 | 53.277870 | 46.488681 | 7.796675 | 8.108885 | -6.382245 | -4.151321 | 0.6616 | 0.6882 | 0.3973 | nan | nan |
| 2459876 | RF_maintenance | 100.00% | 100.00% | 100.00% | 0.00% | - | - | nan | nan | inf | inf | nan | nan | nan | nan | nan | nan | nan | nan | nan |
| 2459875 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 7.651025 | 3.569726 | 51.430332 | 44.034541 | 9.123131 | 11.017697 | -1.678565 | 2.793812 | 0.6960 | 0.7076 | 0.3875 | nan | nan |
| 2459874 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 10.743167 | 5.427929 | 26.537374 | 22.434743 | 12.316945 | 13.265743 | -4.909194 | -4.143512 | 0.6885 | 0.6789 | 0.3739 | nan | nan |
| 2459873 | RF_maintenance | 100.00% | 0.00% | 0.00% | 0.00% | - | - | 7.836192 | 3.746421 | 36.046747 | 30.543727 | 4.428622 | 5.636161 | -3.344711 | -2.668343 | 0.6915 | 0.6801 | 0.3763 | nan | nan |
auto_metrics notebooks.¶htmls_to_display = []
for am_html in auto_metric_htmls:
html_to_display = ''
# read html into a list of lines
with open(am_html) as f:
lines = f.readlines()
# find section with this antenna's metric plots and add to html_to_display
jd = [int(s) for s in re.split('_|\.', am_html) if s.isdigit()][-1]
try:
section_start_line = lines.index(f'<h2>Antenna {antenna}: {jd}</h2>\n')
except ValueError:
continue
html_to_display += lines[section_start_line].replace(str(jd), f'<a href="{jd_to_auto_metrics_url(jd)}" target="_blank">{jd}</a>')
for line in lines[section_start_line + 1:]:
html_to_display += line
if '<hr' in line:
htmls_to_display.append(html_to_display)
break
These figures are reproduced from auto_metrics notebooks. For more info on the specific plots and metrics, see those notebooks (linked at the JD). The most recent 100 days (at most) are shown.
for i, html_to_display in enumerate(htmls_to_display):
if i == 100:
break
display(HTML(html_to_display))
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 4.918153 | 1.674202 | 4.441880 | 3.414487 | 4.918153 | 2.331525 | 4.279715 | -2.022963 | -3.155565 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 40.963812 | 4.072724 | 6.764173 | 35.699041 | 40.963812 | 5.244433 | 5.155861 | -2.669634 | -5.801580 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 48.706503 | 6.462622 | 10.603717 | 41.679123 | 48.706503 | 7.432229 | 7.465988 | -0.488427 | -2.407451 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 54.537059 | 4.055062 | 7.002903 | 47.129606 | 54.537059 | 14.298215 | 14.796149 | 1.281351 | -5.027361 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 43.768277 | 4.330927 | 7.570058 | 38.030318 | 43.768277 | 4.461798 | 4.476612 | -2.126402 | -3.322607 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Shape | 3.172394 | 0.795421 | 3.172394 | 0.759708 | 2.108286 | -1.563879 | -0.431426 | -3.254741 | -4.344997 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 53.277870 | 4.719113 | 7.292762 | 46.488681 | 53.277870 | 8.108885 | 7.796675 | -4.151321 | -6.382245 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Shape | nan | nan | nan | inf | inf | nan | nan | nan | nan |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 51.430332 | 7.651025 | 3.569726 | 51.430332 | 44.034541 | 9.123131 | 11.017697 | -1.678565 | 2.793812 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 26.537374 | 10.743167 | 5.427929 | 26.537374 | 22.434743 | 12.316945 | 13.265743 | -4.909194 | -4.143512 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 139 | N13 | RF_maintenance | ee Power | 36.046747 | 7.836192 | 3.746421 | 36.046747 | 30.543727 | 4.428622 | 5.636161 | -3.344711 | -2.668343 |